# 操作图片
# https://www.bilibili.com/video/BV19T4y127Z2?p=8&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
import numpy as np
from scipy import ndimage
from scipy import misc
#from scipy import datasets
import matplotlib.pyplot as plt

print("操作图片")

# DeprecationWarning: scipy.misc.face has been deprecated in SciPy v1.10.0; and will be completely removed in SciPy v1.12.0. Dataset methods have moved into the scipy.datasets module. Use scipy.datasets.face instead.
f = misc.face()
print(f.shape)
print(type(f))

# 在PyCharm中貌似不好使，在JupyterLab中尝试一下
# 202302141804 果然在JuypterLab中可以显示。
plt.imshow(f)

a = f[0:384, 0:512, :]
plt.imshow(a)

# 图片分割成上下两部分
a1, a2 = np.split(f, 2)
plt.imshow(a1)
plt.imshow(a2)

# 图片分割成左右两部分
b1, b2 = np.split(f, 2, axis=1)
plt.imshow(b1)
plt.imshow(b2)

# 合并
plt.imshow(np.concatenate((a1, a2)))

# 将指定区域的R都变为255
f1 = f.copy()
f1[100:300, :, 0] = 255
plt.imshow(f1)

# 将RGB都设为255
f1 = f.copy()
f1[100:300, :, ...] = 255
plt.imshow(f1)

# 将RGB都设为255 写法2
f1 = f.copy()
f1[100:300, :] = 255
plt.imshow(f1)

# 将RGB都设为0 写法2
f1 = f.copy()
f1[100:300, :] = 0
plt.imshow(f1)

